package com.kexio.auth.dto;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.io.Serializable;
import java.util.List;

/**
 * 菜单信息DTO
 * 
 * 封装用户可见菜单的层级结构和基本信息
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MenuInfo implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    /**
     * 菜单ID - UUID字符串
     */
    private String id;
    
    /**
     * 父菜单ID - UUID字符串
     */
    private String parentId;
    
    /**
     * 菜单名称（路由名称，如 dashboard）
     */
    private String name;
    
    /**
     * 菜单标题（显示名称，如 "仪表板"）
     */
    private String title;
    
    /**
     * 菜单路径
     */
    private String path;
    
    /**
     * 前端组件路径
     */
    private String component;
    
    /**
     * 菜单图标
     */
    private String icon;
    
    /**
     * 排序号
     */
    private Integer orderNo;
    
    /**
     * 菜单类型：M-目录，C-菜单，F-按钮
     */
    private String menuType;
    
    /**
     * 是否可见
     */
    private Boolean visible;
    
    /**
     * 菜单状态：1-启用，0-禁用
     */
    private Integer status;
    
    /**
     * 权限标识
     */
    private String permission;
    
    /**
     * 子菜单列表
     */
    private List<MenuInfo> children;
    
    /**
     * 元数据（额外配置信息）
     */
    private MenuMeta meta;
    
    // ==================== 构造函数 ====================
    
    public MenuInfo() {}
    
    public MenuInfo(String id, String name, String path) {
        this.id = id;
        this.name = name;
        this.path = path;
    }
    
    public MenuInfo(String id, String parentId, String name, String path, String component) {
        this(id, name, path);
        this.parentId = parentId;
        this.component = component;
    }
    
    // ==================== 便捷方法 ====================
    
    /**
     * 判断是否为根菜单
     */
    public boolean isRootMenu() {
        return parentId == null || "0".equals(parentId);
    }
    
    /**
     * 判断是否有子菜单
     */
    public boolean hasChildren() {
        return children != null && !children.isEmpty();
    }
    
    /**
     * 判断菜单是否可见
     */
    public boolean isVisible() {
        return visible != null && visible;
    }
    
    /**
     * 判断菜单是否启用
     */
    public boolean isEnabled() {
        return status != null && status == 1;
    }
    
    /**
     * 判断是否为目录
     */
    public boolean isDirectory() {
        return "M".equals(this.menuType);
    }
    
    /**
     * 判断是否为菜单
     */
    public boolean isMenu() {
        return "C".equals(this.menuType);
    }
    
    /**
     * 判断是否为按钮
     */
    public boolean isButton() {
        return "F".equals(this.menuType);
    }
    
    // ==================== 内部类：菜单元数据 ====================
    
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public static class MenuMeta implements Serializable {
        private String title;
        private String icon;
        private Boolean keepAlive;
        private Boolean requiresAuth;
        private String[] roles;
        private Boolean hideInMenu;
        private String target;
        
        public MenuMeta() {}
        
        public MenuMeta(String title, String icon) {
            this.title = title;
            this.icon = icon;
        }
        
        // Getter/Setter
        public String getTitle() { return title; }
        public void setTitle(String title) { this.title = title; }
        public String getIcon() { return icon; }
        public void setIcon(String icon) { this.icon = icon; }
        public Boolean getKeepAlive() { return keepAlive; }
        public void setKeepAlive(Boolean keepAlive) { this.keepAlive = keepAlive; }
        public Boolean getRequiresAuth() { return requiresAuth; }
        public void setRequiresAuth(Boolean requiresAuth) { this.requiresAuth = requiresAuth; }
        public String[] getRoles() { return roles; }
        public void setRoles(String[] roles) { this.roles = roles; }
        public Boolean getHideInMenu() { return hideInMenu; }
        public void setHideInMenu(Boolean hideInMenu) { this.hideInMenu = hideInMenu; }
        public String getTarget() { return target; }
        public void setTarget(String target) { this.target = target; }
    }
    
    // ==================== Getter/Setter ====================
    
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
    
    public String getParentId() {
        return parentId;
    }
    
    public void setParentId(String parentId) {
        this.parentId = parentId;
    }
    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
    
    public String getPath() {
        return path;
    }
    
    public void setPath(String path) {
        this.path = path;
    }
    
    public String getComponent() {
        return component;
    }
    
    public void setComponent(String component) {
        this.component = component;
    }
    
    public String getIcon() {
        return icon;
    }
    
    public void setIcon(String icon) {
        this.icon = icon;
    }
    
    public Integer getOrderNo() {
        return orderNo;
    }
    
    public void setOrderNo(Integer orderNo) {
        this.orderNo = orderNo;
    }
    
    public String getMenuType() {
        return menuType;
    }
    
    public void setMenuType(String menuType) {
        this.menuType = menuType;
    }
    
    public Boolean getVisible() {
        return visible;
    }
    
    public void setVisible(Boolean visible) {
        this.visible = visible;
    }
    
    public Integer getStatus() {
        return status;
    }
    
    public void setStatus(Integer status) {
        this.status = status;
    }
    
    public String getPermission() {
        return permission;
    }
    
    public void setPermission(String permission) {
        this.permission = permission;
    }
    
    public List<MenuInfo> getChildren() {
        return children;
    }
    
    public void setChildren(List<MenuInfo> children) {
        this.children = children;
    }
    
    public MenuMeta getMeta() {
        return meta;
    }
    
    public void setMeta(MenuMeta meta) {
        this.meta = meta;
    }
    
    @Override
    public String toString() {
        return "MenuInfo{" +
                "id='" + id + '\'' +
                ", parentId='" + parentId + '\'' +
                ", name='" + name + '\'' +
                ", path='" + path + '\'' +
                ", component='" + component + '\'' +
                ", icon='" + icon + '\'' +
                ", orderNo=" + orderNo +
                ", menuType='" + menuType + '\'' +
                ", visible=" + visible +
                ", status=" + status +
                ", permission='" + permission + '\'' +
                ", children=" + children +
                ", meta=" + meta +
                '}';
    }
}
